﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Text;

namespace WebApplication2.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }

        [HttpGet]
        [Route("basicAuth")]
        public ActionResult BasicAuth()
        {
            var auth = this.Request.Headers["Authorization"];
            var credential = GetCredential();
            if(credential == auth)
            {
                return Ok();
            }
            else
            {
                return Unauthorized();
            }
        }

        private string GetCredential()
        {
            var content = Convert.ToBase64String(Encoding.ASCII.GetBytes($"test:test"));
            return $"Basic {content}";
        }
    }
}
